define(function(require, exports){
	var $		= require("jquery");
	var pubjs	= require('pubjs');
	var view	= require('@base/view');
	var util	= require('util');

	var Base = view.widget.extend({
		init: function(config)
		{
			config = pubjs.conf( config, {
				"addUrl": 'qualification/add',
				"layout": {
					"module": '@base/dialog.base',
					"mask": 1,
					"title": LANG('新建资质'),
					"showFoot": true, // 显示底层的取消和完成按钮
					"width": 500,
					"close": null,
					"silence": false, // 点击按钮发消息
					"size": 'ms'
				},
				'vModel': {
					'Name': ''
				},
				'vLazy': true
			});
			this.Super( 'init', arguments );
		},
		afterBuild:function()
		{
			var el = this.getDOM();
			$([
				'<div class="P-qualificationAdd">',
					'<div class="M-formConGroup">',
						'<label class="group-label">' + LANG('资质名称：') + '</label>',
						'<input class="w250" type="text" v-model="Name">',
					'</div>',
				'</div>'
			].join('')).appendTo(el);
			this.buildFromTemplate({
			});
			
			this.vm.mount();
		},
		getData: function()
		{
			var vm = this.vm.$data;
			return {
				'Name': util.trim(vm.Name)
			};
		},
		reset: function()
		{
			this.vm.reset();
			return this;
		},
		save: function()
		{
			var data = this.getData();

			if(this.validate(data))
			{
				this.showLoading();
				var c = this.getConfig();
				pubjs.mc.send(c.addUrl, data, this.onSave.bind(this));
			}
		},
		onSave: function(err, data)
		{
			this.hideLoading();
			if(err){
				pubjs.alert(err.message);
				return false;
			}
			pubjs.alert(LANG('新建资质成功'));
			this.reset();
			this.hide();
		},
		//响应点击完成事件
		onDialogOk: function(ev)
		{
			this.save();
		},
		validate: function(data)
		{
			
			if (!data.Name)
			{
				pubjs.alert(LANG('资质名称不能为空'));
				return false;
			}

			return true;
		}
	});
	exports.base = Base;
});